<?php
error_reporting(E_ALL ^ E_NOTICE);
define('LIN_PATH', dirname(__FILE__));//框架的根目录
define("APP_PATH", getcwd());//项目的根目录
define('APP_HOME', str_replace(array("\\", $_SERVER['DOCUMENT_ROOT']), array("/", ""), getcwd()));//项目的顶级 URL
include_once(dirname(__FILE__)."/function/base.func.php");

if(is_file(APP_PATH . '/const.php')){
    include_once(APP_PATH . '/const.php');
}

ob_start();
session_start();
set_exception_handler('lin_exception_handler');

//解析URL, URL的格式如: index.php/default-index/age-20/country-china 其等价于 index.php?mod=default&act=index&age=20&country=china
if(!empty($_SERVER['PATH_INFO'])){
    $args = explode("/", trim($_SERVER['PATH_INFO'], "/"));
    $module = array_shift($args);
    list($mod, $act) = explode("-", $module);
    $_REQUEST['mod'] = $_GET['mod'] = $mod;
    $_REQUEST['act'] = $_GET['act'] = $act;
    foreach($args as $arg){
        list($key, $val) = explode("-", $arg);
        $_REQUEST[$key] = $_GET[$key] = $val;
    }
}
$bootConfig = config('boot');
$defaultController = empty($bootConfig['defaultController'])?   'Default' : ucfirst($bootConfig['defaultController']);
$defaultAction = empty($bootConfig['defaultAction'])?  'index' : $bootConfig['defaultAction'];

//获得控制器名和方法名
$mod = $_REQUEST['mod'] = $_GET['mod'] = (empty($_REQUEST['mod']))?  $defaultController : ucfirst($_REQUEST['mod']);
$act = $_REQUEST['act'] = $_GET['act'] = (empty($_REQUEST['act']))?  $defaultAction : $_REQUEST['act'];
$mod .= 'Controller';
try{
    $mod = new $mod();
    $mod->__before();
    $mod->$act();
    $mod->__after();
}catch(PDOException $e){
    dump($e->getMessage());
}


